﻿using System.ComponentModel.DataAnnotations;

namespace Max.PH4_2104A.Shopping.DTO
{
    /// <summary>
    /// 服务器响应值DTO
    /// </summary>
    public class ResponseResultDto
    {
        private string message;

        public ResponseStateCode Code { get; set; } = ResponseStateCode.Success;
        public string Message
        {
            get
            {
                if (string.IsNullOrEmpty(message))
                {
                    message = this.Code.ToString();

                    var objs = this.Code.GetType().GetField(this.Code.ToString()).GetCustomAttributes(typeof(DisplayAttribute), true);
                    if(objs != null && objs.Length > 0)
                    {
                        message = ((DisplayAttribute)objs[0]).Name;
                    }
                }

                return message;
            }
            set => message = value;
        }
        public dynamic Result { get; set; } //结果
    }

    /// <summary>
    /// 服务器中响应状态码
    /// </summary>
    public enum ResponseStateCode
    {
        Success = 200, //操作成功
        Failed = 500, //服务器错误

        Err_Params = -600, //参数错误

        #region 用户方面
        Err_UserName = -680, //用户名错误
        Err_Password = -681, //密码错误

        [Display(Name = "用户不存在")]
        Err_User_NoExist = -682,//用户不存在
        Err_User_Disable = -683,//用户已禁用
        #endregion
    }
}